<?php

/**
 * This is the model class for table "xman_user_profile".
 *
 * The followings are the available columns in table 'xman_user_profile':
 * @property integer $user_profile_user_id
 * @property string $user_profile_user_name
 * @property string $user_profile_user_bank_account
 * @property string $user_profile_user_date_of_birth
 * @property string $user_profile_user_gender
 * @property string $user_profile_user_idcard
 * @property string $user_profile_user_idcard_date
 * @property integer $user_profile_user_idcard_place
 * @property string $user_profile_phone_number
 * @property string $user_profile_email
 * @property string $user_profile_adress
 * @property string $user_profile_birth_place
 * @property string $user_profile_ethnic
 * @property integer $user_profile_adress_province_id
 * @property integer $user_profile_birth_place_province_id
 *
 * The followings are the available model relations:
 * @property User $userProfileUser
 * @property Province $userProfileUserIdcardPlace
 * @property Province $userProfileAdressProvince
 * @property Province $userProfileBirthPlaceProvince
 */
class UserProfile extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return UserProfile the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'xman_user_profile';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('user_profile_user_id, user_profile_user_name, user_profile_adress_province_id, user_profile_birth_place_province_id', 'required'),
			array('user_profile_user_id, user_profile_user_idcard_place, user_profile_adress_province_id, user_profile_birth_place_province_id', 'numerical', 'integerOnly'=>true),
			array('user_profile_user_name, user_profile_user_bank_account, user_profile_user_gender, user_profile_user_idcard, user_profile_phone_number, user_profile_email, user_profile_ethnic', 'length', 'max'=>100),
			array('user_profile_adress, user_profile_birth_place', 'length', 'max'=>200),
			array('user_profile_user_date_of_birth, user_profile_user_idcard_date', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('user_profile_user_id, user_profile_user_name, user_profile_user_bank_account, user_profile_user_date_of_birth, user_profile_user_gender, user_profile_user_idcard, user_profile_user_idcard_date, user_profile_user_idcard_place, user_profile_phone_number, user_profile_email, user_profile_adress, user_profile_birth_place, user_profile_ethnic, user_profile_adress_province_id, user_profile_birth_place_province_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'userProfileUser' => array(self::BELONGS_TO, 'User', 'user_profile_user_id'),
			'userProfileUserIdcardPlace' => array(self::BELONGS_TO, 'Province', 'user_profile_user_idcard_place'),
			'userProfileAdressProvince' => array(self::BELONGS_TO, 'Province', 'user_profile_adress_province_id'),
			'userProfileBirthPlaceProvince' => array(self::BELONGS_TO, 'Province', 'user_profile_birth_place_province_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'user_profile_user_id' => 'User Profile User',
			'user_profile_user_name' => 'User Profile User Name',
			'user_profile_user_bank_account' => 'User Profile User Bank Account',
			'user_profile_user_date_of_birth' => 'User Profile User Date Of Birth',
			'user_profile_user_gender' => 'User Profile User Gender',
			'user_profile_user_idcard' => 'User Profile User Idcard',
			'user_profile_user_idcard_date' => 'User Profile User Idcard Date',
			'user_profile_user_idcard_place' => 'User Profile User Idcard Place',
			'user_profile_phone_number' => 'User Profile Phone Number',
			'user_profile_email' => 'User Profile Email',
			'user_profile_adress' => 'User Profile Adress',
			'user_profile_birth_place' => 'User Profile Birth Place',
			'user_profile_ethnic' => 'User Profile Ethnic',
			'user_profile_adress_province_id' => 'User Profile Adress Province',
			'user_profile_birth_place_province_id' => 'User Profile Birth Place Province',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('user_profile_user_id',$this->user_profile_user_id);
		$criteria->compare('user_profile_user_name',$this->user_profile_user_name,true);
		$criteria->compare('user_profile_user_bank_account',$this->user_profile_user_bank_account,true);
		$criteria->compare('user_profile_user_date_of_birth',$this->user_profile_user_date_of_birth,true);
		$criteria->compare('user_profile_user_gender',$this->user_profile_user_gender,true);
		$criteria->compare('user_profile_user_idcard',$this->user_profile_user_idcard,true);
		$criteria->compare('user_profile_user_idcard_date',$this->user_profile_user_idcard_date,true);
		$criteria->compare('user_profile_user_idcard_place',$this->user_profile_user_idcard_place);
		$criteria->compare('user_profile_phone_number',$this->user_profile_phone_number,true);
		$criteria->compare('user_profile_email',$this->user_profile_email,true);
		$criteria->compare('user_profile_adress',$this->user_profile_adress,true);
		$criteria->compare('user_profile_birth_place',$this->user_profile_birth_place,true);
		$criteria->compare('user_profile_ethnic',$this->user_profile_ethnic,true);
		$criteria->compare('user_profile_adress_province_id',$this->user_profile_adress_province_id);
		$criteria->compare('user_profile_birth_place_province_id',$this->user_profile_birth_place_province_id);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
	
	public function getGenderList(){
	    return array(
	    	'Chưa xác định'=>'Chưa xác định',
	        'Nam'=>'Nam',
	        'Nữ'=>'Nữ',
	    );
	}
}